package com.dranie.utils;

import org.junit.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * User: xi
 * Date: 13-8-8
 * Time: 下午12:42
 * To change this template use File | Settings | File Templates.
 */
public class ImgBase64Util {

    private final String prefix = "data:image/png;base64,";

    @Test
    public void testBase64() {
        //data:image/png;base64,
        String str = "aaaaaaaaaaaaaa";
        String s = EncryptUtils.base64Encode(str);
        String file = "E:\\app\\dranie\\dranie\\src\\main\\webapp\\web\\res\\images\\tools.png";
        System.out.println(s);
        File f = new File(file);
        try {
            FileInputStream in = new FileInputStream(file);
            byte[] b = new byte[in.available()];
            in.read(b);
            String sf = EncryptUtils.base64Encode(b);
            System.out.println(prefix + sf);
        } catch (FileNotFoundException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }

}
